package com.example.test_notification;

import android.app.Activity;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.TaskStackBuilder;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class ChildActivity extends Activity implements OnClickListener{
	private Button button ;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.child_layout);
		
		button = (Button) findViewById(R.id.button_basic);
		
		button.setOnClickListener(this);
	}
	
	private void fun() {
		// TODO Auto-generated method stub

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
        mBuilder.setSmallIcon(R.drawable.ic_launcher);
        mBuilder.setTicker("New news comes");
        mBuilder.setContentTitle("My Notification");
        mBuilder.setContentText("Notification news content");
        
        Intent resultIntent = new Intent(this, ChildActivity.class);
        
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        stackBuilder.addParentStack(MainActivity.class);
        stackBuilder.addParentStack(ChildActivity.class);
        stackBuilder.addNextIntent(resultIntent);
        
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0	, PendingIntent.FLAG_UPDATE_CURRENT);
        
        mBuilder.setContentIntent(resultPendingIntent);
        
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        
        mNotificationManager.notify(100, mBuilder.getNotification());
	}
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.button_basic:
			fun();
			break;

		default:
			break;
		}
	}
}
